Skip to content

Add helper accessor to return final time slice#315

Merged
dschwoerer merged 3 commits intomasterfrom
final-time
Nov 27, 2025
Merged

Add helper accessor to return final time slice#315
dschwoerer merged 3 commits intomasterfrom
final-time

Conversation

@mikekryjak
Copy link
Collaborator

@mikekryjak mikekryjak commented Aug 7, 2025

This returns the final time slice of a Dataset or DataArray whether the data contains multiple time slices or not. This is helpful when working with multiple simulations, some of which may have only been run for one timestep for developer reasons.

Here is how this can be done with built-in Xarray functionality right now - let's say we are reading in a 1D model, want to get the final timeslice whether the dataset contains time or not, and then snip off guard cells:

ds = ds.isel(t=-1, missing_dims = "ignore")
ds = ds.isel(y = slice(2,-2))

With this PR we can now do:

ds = ds.bout.final_time().isel(y = slice(2,-2))

mikekryjak and others added 2 commits August 7, 2025 11:24
This returns the final time slice of a dataset or dataarray, whether the data contains multiple time slices or not. This is helpful when working with multiple simulations, some of which may have only been run for one timestep for developer reasons.
@ZedThree
Copy link
Member

Could also add a drop_guards() accessor :)

@johnomotani
Copy link
Collaborator

Could also add a drop_guards() accessor :)

I think there's already something like remove_y_boundaries(), although I think I remember it being a little bit flaky...

@mikekryjak
Copy link
Collaborator Author

I have tried to use the existing tools and also found them flaky and slow. Instead, I have a very useful function called clean_guards() which sets the guard cells to zero - great for doing things like domain integrals and 2D plots. This is part of sdtools right now but I am just implementing the same technology into xHermes.

@mikekryjak
Copy link
Collaborator Author

@ZedThree the tests are failing on a segfault, which is not to do with this PR I don't think. Can we merge this in?

@dschwoerer
Copy link
Contributor

The linting error should be easily fixable.
For the segfault, #317 might help, together with pydata/xarray#10788

@dschwoerer dschwoerer merged commit 65e3560 into master Nov 27, 2025
9 of 13 checks passed
@dschwoerer dschwoerer deleted the final-time branch November 27, 2025 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants